package cn.edu.ujn.multiple.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {
	
	@Pointcut("execution(* cn.edu.ujn.multiple.*.*.*(..))")
	private void myPointcut() {}
	
	@Around("myPointcut()")
	public Object myAround(ProceedingJoinPoint jp) throws Throwable{
		System.out.println("类："+jp.getTarget().getClass()+"——————"+jp.getSignature().getName()+"方法开始执行...");
		Object obj = jp.proceed();
		System.out.println("类："+jp.getTarget().getClass()+"——————"+jp.getSignature().getName()+"方法执行结束...");
		return obj;
	}
	
	@AfterThrowing(value="myPointcut()", throwing="e")
	public void myAfterThrowing(JoinPoint jp, Throwable e) {
		System.out.println("异常通知：出错！"+e.getMessage());
	}
}
